 /*///////////////////////////////////////////////////////////////////////////////
-- Author:      liuhx
-- Created:     Wed Nov 28 11:53:41 CST 2018
-- Description:	    
-- If you have any question,please email to liuhx@gentlesoft.com.cn 
////////////////////////////////////////////////////////////////////////////////*/
package com.ctsi.question.controller;

 import com.ctsi.commons.util.UtilValidate;
 import com.ctsi.commons.util.id.UUIDGenerator;
 import com.ctsi.framework.common.response.UnifiedResponse;
 import com.ctsi.framework.security.util.SecurityUtil;
 import com.ctsi.organise.common.api.PersonServiceProxy;
 import com.ctsi.organise.common.model.Organise;
 import com.ctsi.question.entity.Expert;
 import com.ctsi.question.entity.HangyeLevel1;
 import com.ctsi.question.entity.ZhuanJiaList;
 import com.ctsi.question.service.ExpertService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.ResponseStatus;
 import org.springframework.web.bind.annotation.RestController;

 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;

 /**
 * Expert Controller 类
 * @author   liuhx
 * @description  Expert
 * @created	 Wed Nov 28 11:53:41 CST 2018
 */
@RestController
public class ExpertController {
	private static final Logger logger=LoggerFactory.getLogger(ExpertController.class);
	@Autowired
	private ExpertService expertService;
     @Autowired
     private PersonServiceProxy personServiceProxy;
	/*
	* @专家，加入问题与专家中间表
	* */
	@PostMapping(value = "/expert/addExpert",consumes = "application/json",produces = "application/json;charset=UTF-8")
	 @ResponseStatus(HttpStatus.OK)
	 public UnifiedResponse<Integer> addExpert(@RequestBody Expert expert){
			expert.setId(UUIDGenerator.getId());
			expert.setIs_default(0);
			int i = expertService.insertExpert(expert);
			return UnifiedResponse.ok(i);
		}

		/*
		* 查询该用户所属组织对应的专家
		* */
		@PostMapping(value = "/expert/selectZhuanJiaList",produces = "application/json;charset=UTF-8")
        @ResponseStatus(HttpStatus.OK)
     public UnifiedResponse<List<HangyeLevel1>> selectZhuanJiaList(){
            Organise organise4User = personServiceProxy.getOrganise4User(SecurityUtil.getUser().getUserId());
            if (UtilValidate.isEmpty(organise4User.getPartyId())){
                return UnifiedResponse.ok(null);
            }else {
                String organid = organise4User.getPartyId();
                Map<String,Object> map=new HashMap<>();
                map.put("organid",organid);
                List<HangyeLevel1> level1 = expertService.selectDicTreeLevel1();
                for (HangyeLevel1 aLevel1 : level1) {
                    String CODE_ = aLevel1.getCode_();
                    String NAME_ = aLevel1.getName_();
                    map.put("code_", CODE_);
                    map.put("name_", NAME_);
                    List<ZhuanJiaList> zhuanJiaLists = expertService.selectZhuanJiaList(map);
                    ZhuanJiaList zhuanJiaList=new ZhuanJiaList();
                    zhuanJiaList.setSelect(0);
                    aLevel1.setZhuanJiaList(zhuanJiaLists);
                }
                return UnifiedResponse.ok(level1);
            }
        }
}
